package ca.swank.hardquor;

import java.net.*;
import java.io.*;
import java.util.StringTokenizer;
import java.util.ArrayList;

public class hardquorInternetTools
{

  public static String[][] getGameServerList(String url)
  {
	ArrayList servers = new ArrayList();

    try
    { URL serverList = new URL(url);
      BufferedReader in = new BufferedReader(new InputStreamReader(serverList.openStream()));

	  String line;

	  while ((line = in.readLine()) != null)
      { StringTokenizer tok = new StringTokenizer(line,"= :\t");
        String[] lineServer = new String[2];
        if(tok.hasMoreTokens())
        { lineServer[0] = tok.nextToken();
          if(tok.hasMoreTokens())
          { lineServer[1] = tok.nextToken();
            servers.add(lineServer);
	      }
	    }
      }
      in.close();
    } catch(MalformedURLException e)
    { System.out.println("Malformed URL: " + url + "; no hardquor game servers found");
      return new String[0][];
    } catch(IOException e)
    { System.out.println("Error loading URL: " + url + "; no hardquor game servers found");
      return new String[0][];
    }

    return (String[][])servers.toArray(new String[][] { });

  }


}
